package com.bustle.product.proxy;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.commons.JsonParser;
import com.bustle.commons.data.dao.Dao;
import com.bustle.commons.data.dao.DaoProxy;
import com.bustle.commons.http.RestDtoDaoProxy;
import com.bustle.commons.http.TypeToJsonHttpConverter;
import com.bustle.product.dto.provider.ProviderDto;
import com.bustle.product.dto.provider.ProviderDtoDaoWebService.ProviderDtoList;
import com.bustle.product.dto.provider.ProviderDtoMapper;

@Local
public interface ProviderDtoDaoProxy extends Dao<Integer, ProviderDto>
{
  @Stateless
  public class DefaultProviderDtoDaoProxy extends DaoProxy<Integer, ProviderDto, Dao<Integer, ProviderDto>> implements ProviderDtoDaoProxy
  {
    @PostConstruct
    public void postBuild()
    {
      dao = new RestDtoDaoProxy<Integer, ProviderDto>("localhost", 8080, "provider", new JsonParser(), new TypeToJsonHttpConverter<>(ProviderDto.class), ProviderDto.class, dtoMapper)
        {
          @Override
          protected List<ProviderDto> retrieveAllFrom(String aResult)
          {
            return parser.parse(ProviderDtoList.class, aResult).getProvider();
          }
        };
    }

    @EJB
    protected ProviderDtoMapper dtoMapper;
  }
}
